package vn.edu.hut.soict.automaton;

public class Transition<T> {
	private State<T> source;
	private State<T> target;
	private T symbol;

	public Transition(State<T> source, State<T> target, T symbol) {
		this.source = source;
		this.target = target;
		this.symbol = symbol;
	}

	public State<T> getSource() {
		return source;
	}

	public void setSource(State<T> source) {
		this.source = source;
	}

	public State<T> getTarget() {
		return target;
	}

	public void setTarget(State<T> target) {
		this.target = target;
	}

	public synchronized T getSymbol() {
		return symbol;
	}

	public synchronized void setSymbol(T symbol) {
		this.symbol = symbol;
	}

	public boolean equals(Object obj) {
		if (obj instanceof Transition) {
			Transition t = (Transition) obj;
			return (source == t.source && target == t.target && symbol.equals(t.symbol));
		}
		else {
			return false;
		}
	}

	public String toString() {
		return String.format("(%d--%s->%d)", source.getId(), symbol.toString(), target.getId());
	}

	public boolean isEquivalent(Transition<T> transition) {
		return (this.target == transition.target && this.symbol.equals(transition.symbol));
	}
}
